﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SimpleFileManager.Manager
{
    public class File : FilePanelItem
    {
        private long _size;
        private DateTime _lastAccessTime;

        public File(string name,long size, DateTime lastAccessTime,IFolderIterator iterator)
            : base(name,FilePanelItemType.File,iterator)
        {
            _size = size;
            _lastAccessTime = lastAccessTime;
        }

        public override long Size
        {
            get { return _size; }
        }

        public override DateTime LastAccessTime
        {
            get { return _lastAccessTime; }
        }

        public override void Add(IFilePanelItem item)
        {
        }

        public override void Remove(IFilePanelItem item)
        {
        }

        public override void Copy(string path)
        {
            System.IO.File.Copy(Path.Combine(Iterator.DirectoryPath, Name), Path.Combine(path, Name));
        }

        public override void Delete()
        {
            System.IO.File.Delete(Path.Combine(Iterator.DirectoryPath + Name));
        }

        public override void Move(string path)
        {
            Copy(path);
            Delete();
        }

        public override void MakeAction(Manager.FileManager.FilePanel filePanel)
        {
            try
            {
                System.Diagnostics.Process.Start(Path.Combine(Iterator.DirectoryPath,Name));
            }
            catch (Exception)
            {
                throw;
            }
        }

        public override void Create(string name)
        {
        }

        public override void Rename(string newName)
        {
            System.IO.File.Move(Path.Combine(Iterator.DirectoryPath,Name),Path.Combine(Iterator.DirectoryPath,newName));
        }

    }
}
